import axios from 'axios'
import qs from 'qs'

export default {
    namespaced: true,
    actions: {
        getPageType: function ({commit}, params) {
            let {callback} = params;
            params.onget = ({data}) => {
                callback(data);
            }
            commit("getPageType", params);
        },
        getAllPageType: function ({commit}, params) {
            let {callback} = params;
            params.onget = ({data}) => {
                callback(data);
            }
            commit("getAllPageType", params);
        },
        addPageType: function ({commit}, params) {
            let {callback} = params;
            params.onget = ({data}) => {
                callback(data);
            }
            commit("addPageType", params);
        },
        updatePageType: function ({commit}, params) {
            let {callback} = params;
            params.onget = ({data}) => {
                callback(data);
            }
            commit("updatePageType", params);
        },
        deletePageType: function ({commit}, params) {
            let {callback} = params;
            params.onget = ({data}) => {
                callback(data);
            }
            commit("deletePageType", params);
        },
    },
    mutations: {
        getPageType: function (state, {id, onget}) {
             axios.get(`/admin/pagetype/${id}`).then(data => {
                onget(data);
            })
        },
         getAllPageType: function (state, { onget,page,size,name}) {
             axios.get(`/admin/pagetype`,{
                params:{
                    page,size,name
                }
            }).then(data => {
                onget(data);
            })
        },
        addPageType: function (state, { name,onget}) {
            axios.post(`/admin/pagetype`, qs.stringify({
                name
            })).then(data => {
                onget(data);
            })
        },
        updatePageType: function (state, {onget,id, name }) {
             axios.put(`/admin/pagetype`, {
                    id,name
            }).then(data => {
                onget(data);
            })
        },

        deletePageType: function (state, {id, onget}) {
			axios.delete(`/admin/pagetype`,{
                params:{
                    id
                }
            }).then(data => {
				onget(data);
			});
		},
    }

}